import get from '@dfeidao/atom-web/global/get';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from '@dfeidao/atom-web/url/refresh';
import { productid } from '../../atom/config';
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// todo
	const staff_no = get('staff_no');
	const staff_name = get('staff_name');

	const time2 = new Date();
	const time = new Date(time2).getTime();

	const unitNO = fd.data.node.querySelector<HTMLSelectElement>('[data-id="xm"]');
	const project_no = unitNO.value;

	let project_name = "";
	if (!project_no) {
		alert("请选择项目名称！");
		return;
	} else {
		project_name = unitNO.selectedOptions[0].text;
	}

	const project_asset_no1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="project_asset_no"]');
	const project_asset_no = project_asset_no1.value;

	const assetsname1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="assetsname"]');
	const assetsname = assetsname1.value;

	const brand_no1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="brand_no"]');
	const brand_no = brand_no1.value;

	const pdname1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="pdname"]');
	const pdname = pdname1.value;

	if (pdname === "" || project_no === "") {
		alert("带*号的为必填项");
		return;
	}

	const res = await nodejs<{ code: 0 | 1; result: string }>('inventory-of-assets/zj-000002/s003', {
		filter: {
			productid,
			project_id: project_no,
			project_name,
			inventory_time: time,
			inventory_people: staff_name,
			inventory_people_no: staff_no,
			lnventory_name: pdname,
			assetsname,
			brand_no,
			project_asset_no
		}
	});
	if (res.code === 1) {
		alert("添加成功");
		refresh();
	} else {
		alert("添加失败");
	}
}
